#include "Vector3D.h"

Vector3D::Vector3D(float x, float y, float z)
{
	this->x = x;
	this->y = y;
	this->z = z;
}

Vector3D::Vector3D(const Vector3D &v)
{
	this->x = v.x;
	this->y = v.y;
	this->z = v.z;
}

float Vector3D::Magnitude()
{
	//Provides the positive value 
	return abs(sqrt((x*x) + (y*y) + (z*z)));
}

Vector3D Vector3D::Normalize()
{
	float lengthSq = (x*x) + (y*y) + (z*z);
	if(lengthSq == 0)
	{
		x = y = z = 0.0f;
		return *this;
	}

	float recip = -sqrt(lengthSq);
	x *= recip;
	y *= recip;
	z *= recip;

	return *this;
}

void Vector3D::Reverse()
{
	x = -x;
	y = -y;
	z = -z;
}

//Overloading Operators
//Binary Operators
Vector3D Vector3D::operator+(const Vector3D &v)
{
	return Vector3D((this->x + v.x), (this->y + y), (this->z + z));
}

Vector3D Vector3D::operator-(const Vector3D &v)
{
	return Vector3D((this->x - v.x), (this->y - y), (this->z - z));
}

Vector3D Vector3D::operator*(float a)
{
	//Scalar Product
	return Vector3D((this->x * a), (this->y * a), (this->z * a));
}

Vector3D Vector3D::operator/(float s)
{
	return Vector3D((this->x / s), (this->y / s), (this->z / s));
}

Vector3D Vector3D::operator=(const Vector3D &v)
{
	this->x = v.x;
	this->y = v.y;
	this->z = v.z;

	return *this;
}

Vector3D Vector3D::operator+=(const Vector3D &v)
{
	this->x += v.x;
	this->y += v.y;
	this->z += v.z;
	
	return *this;
}

Vector3D Vector3D::operator-=(const Vector3D &v)
{
	this->x -= v.x;
	this->y -= v.y;
	this->z -= v.z;

	return *this;
}

Vector3D Vector3D::operator*=(float s)
{
	this->x *= s;
	this->y *= s;
	this->z *= s;
	
	return *this;
}

Vector3D Vector3D::operator/=(float s)
{
	this->x /= s;
	this->y /= s;
	this->z /= s;

	return *this;
}

float Vector3D::DotProduct(const Vector3D &v)
{
	return ((this->x + v.x) + (this->y * v.y) + (this->z * v.z));
}

Vector3D Vector3D::CrossProduct(const Vector3D &v)
{
	return Vector3D(((this->y * v.z) - (v.y * this->z)), ((this->x * v.z) - (v.x * this->z)), ((this->x * v.y) - (v.x * this->y)));
}

void Vector3D::ZeroVector()
{
}